﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using POSSystem.BLL;

namespace ShopOnline
{
    public partial class SlideShow : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            if (!string.IsNullOrEmpty(Request.QueryString["slideshow"]) && !string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                int id = int.Parse(Request.QueryString["id"]);
                ShopOnline.BLL.SlideShow slides = new ShopOnline.BLL.SlideShow();
                slides.LoadAll();
                if (slides.RowCount > 0)
                {
                    litGallery.Text = "";
                    string temp = "<a href='{0}' ><img title='{1}' alt='{2}' src='{3}' /></a>";

                    slides.Filter = "ID = " + id.ToString();
                    litGallery.Text += string.Format(temp, POSSystem.BLL.Utilities.GetConfigAppSetting("SlideShowArchive") + "/" + slides.FileName, slides.s_Description, "picture not available", POSSystem.BLL.Utilities.GetConfigAppSetting("SlideShowArchive") + "/" + slides.FileName);

                    slides.Filter = "ID <> " + id.ToString();
                    for (int i = 0; i < slides.RowCount; i++)
                    {
                        litGallery.Text += string.Format(temp, POSSystem.BLL.Utilities.GetConfigAppSetting("SlideShowArchive") + "/" + slides.FileName, slides.s_Description, "picture not available", POSSystem.BLL.Utilities.GetConfigAppSetting("SlideShowArchive") + "/" + slides.FileName);
                        slides.MoveNext();
                    }
                }
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["banner"]) && !string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                int id = int.Parse(Request.QueryString["id"]);
                ShopOnline.BLL.PageBanners banners = new ShopOnline.BLL.PageBanners();
                banners.LoadAll();
                if (banners.RowCount > 0)
                {
                    litGallery.Text = "";
                    string temp = "<a href='{0}' ><img title='{1}' alt='{2}' src='{3}' /></a>";

                    banners.Filter = "ID = " + id.ToString();
                    litGallery.Text += string.Format(temp, POSSystem.BLL.Utilities.GetConfigAppSetting("BannerArchive") + "/" + banners.FileName, banners.s_Description, "picture not available", POSSystem.BLL.Utilities.GetConfigAppSetting("BannerArchive") + "/" + banners.FileName);

                    banners.Filter = "ID <> " + id.ToString();
                    for (int i = 0; i < banners.RowCount; i++)
                    {
                        litGallery.Text += string.Format(temp, POSSystem.BLL.Utilities.GetConfigAppSetting("BannerArchive") + "/" + banners.FileName, banners.s_Description, "picture not available", POSSystem.BLL.Utilities.GetConfigAppSetting("BannerArchive") + "/" + banners.FileName);
                        banners.MoveNext();
                    }
                }
            }
            else if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                int id = int.Parse(Request.QueryString["id"]);
                ProductImages img = new ProductImages();
                img.LoadByPrimaryKey(id);

                if (img.RowCount > 0)
                {
                    litGallery.Text = "";
                    string temp = "<a href='{0}' ><img title='{1}' alt='{2}' src='{3}' /></a>";

                    litGallery.Text += string.Format(temp, POSSystem.BLL.Utilities.GetConfigAppSetting("ProductImagePath") + "/" + img.s_OriginalUrl.Replace("~/", ""), img.s_Description, "picture not available", POSSystem.BLL.Utilities.GetConfigAppSetting("ProductImagePath") + "/" + img.s_ThumbUrl.Replace("~/", ""));

                    if (string.IsNullOrEmpty(Request.QueryString["unique"]))
                    {
                        ProductImages imgs = ProductImages.GetProductPictures(img.ProductID);
                        for (int i = 0; i < imgs.RowCount; i++)
                        {
                            if (imgs.ID != id)
                            {
                                litGallery.Text += string.Format(temp, POSSystem.BLL.Utilities.GetConfigAppSetting("ProductImagePath") + "/" + imgs.s_OriginalUrl.Replace("~/", ""), imgs.s_Description, "picture not available", POSSystem.BLL.Utilities.GetConfigAppSetting("ProductImagePath") + "/" + imgs.s_ThumbUrl.Replace("~/", ""));
                            }
                            imgs.MoveNext();
                        }
                    }
                }
            }
        }
    }
}